package com.weiadmin.controller.api;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.weiadmin.common.BaseController;
import com.weiadmin.dao.SlideDao;
import com.weiadmin.service.ExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 小程序端接口文档
 *
 * @author: shizhongyu
 * @date: 2023年06月07日 12:04
 */
@RestController
@RequestMapping("/api/wxapp")
public class WxappController extends BaseController {
    @Autowired
    SlideDao slideDao;

    @Autowired
    ExcelService excelService;
    @GetMapping("/findSetting")
    public ResponseEntity<?> findSetting() {
       return success("请求成功！");
    }
    @GetMapping("/findSlide")
    public ResponseEntity<?> findSlide(String slide_id) {
//        slideDao.
        return success("请求成功！");
    }

    @GetMapping("/importUser")
    public ResponseEntity<?> importUser(String slide_id) {
        //测试下导入数据
        String path = "G:/code_preview/java_study/study/upload/images/2c76e2fc-10cd-4423-8704-eaaa2e64c759.xlsx";
        List<Map<String,Object>> list = excelService.importExcel(path);
        //也可以读取到Bean
//        List<Person> all = reader.readAll(Person.class);

        return success("导入成功！",list);
    }

    @GetMapping("/exportUser")
    public ResponseEntity<?> exportUser(String slide_id) {
        List<String> row1 = CollUtil.newArrayList("username", "phone", "sex", "createTime");
        List<String> row2 = CollUtil.newArrayList("aa1", "bb1", "cc1", "dd1");
        List<String> row3 = CollUtil.newArrayList("aa2", "bb2", "cc2", "dd2");
        List<String> row4 = CollUtil.newArrayList("aa3", "bb3", "cc3", "dd3");
        List<String> row5 = CollUtil.newArrayList("aa4", "bb4", "cc4", "dd4");

        List<List<String>> rows = CollUtil.newArrayList(row1, row2, row3, row4, row5);
        String path = excelService.exportExcel(rows,"测试会员导出");
        JSONObject jsonResult = JSONUtil.createObj();
        jsonResult.putOnce("path",path);
        return success("导出成功！",jsonResult);
    }

}
